﻿using System;
using System.Collections.Generic;
using System.IO;
using Character;
using UnityEngine;

namespace Studio
{
	// Token: 0x0200049E RID: 1182
	public class OICharInfo : ObjectInfo
	{
		// Token: 0x06001D86 RID: 7558 RVA: 0x000BB230 File Offset: 0x000B9430
		public OICharInfo(CustomParameter _charFile, int _key) : base(_key)
		{
			bool[] array = new bool[7];
			array[1] = true;
			array[3] = true;
			this.activeFK = array;
			this.expression = new bool[4];
			this.animeSpeed = 1f;
			this.animePattern = new float[2];
			this.animeOptionVisible = true;
			this.voiceCtrl = new VoiceCtrl();
			this.siru = new byte[5];
			this.animeOptionParam = new float[2];
			//base.ctor(_key);
			this.sex = ((_charFile == null) ? 0 : ((_charFile.Sex != SEX.FEMALE) ? 0 : 1));
			this.charFile = _charFile;
			this.fileStatus = new CharFileStatus();
			this.bones = new Dictionary<int, OIBoneInfo>();
			this.ikTarget = new Dictionary<int, OIIKTargetInfo>();
			this.child = new Dictionary<int, List<ObjectInfo>>();
			int num = Enum.GetNames(typeof(OICharInfo.AccessoryPoint)).Length;
			for (int i = 0; i < num; i++)
			{
				this.child[i] = new List<ObjectInfo>();
			}
			if (this.sex == 0)
			{
				this.simpleColor = Color.blue;
			}
			this.dicAccessGroup = new Dictionary<int, TreeNodeObject.TreeState>();
			this.dicAccessNo = new Dictionary<int, TreeNodeObject.TreeState>();
		}

		// Token: 0x17000319 RID: 793
		// (get) Token: 0x06001D87 RID: 7559 RVA: 0x000BB394 File Offset: 0x000B9594
		public override int kind
		{
			get
			{
				return 0;
			}
		}

		// Token: 0x1700031A RID: 794
		// (get) Token: 0x06001D88 RID: 7560 RVA: 0x000BB398 File Offset: 0x000B9598
		// (set) Token: 0x06001D89 RID: 7561 RVA: 0x000BB3A0 File Offset: 0x000B95A0
		public int sex { get; private set; }

		// Token: 0x1700031B RID: 795
		// (get) Token: 0x06001D8A RID: 7562 RVA: 0x000BB3AC File Offset: 0x000B95AC
		// (set) Token: 0x06001D8B RID: 7563 RVA: 0x000BB3B4 File Offset: 0x000B95B4
		public CustomParameter charFile { get; set; }

		// Token: 0x1700031C RID: 796
		// (get) Token: 0x06001D8C RID: 7564 RVA: 0x000BB3C0 File Offset: 0x000B95C0
		// (set) Token: 0x06001D8D RID: 7565 RVA: 0x000BB3C8 File Offset: 0x000B95C8
		public CharFileStatus fileStatus { get; set; }

		// Token: 0x1700031D RID: 797
		// (get) Token: 0x06001D8E RID: 7566 RVA: 0x000BB3D4 File Offset: 0x000B95D4
		// (set) Token: 0x06001D8F RID: 7567 RVA: 0x000BB3DC File Offset: 0x000B95DC
		public Dictionary<int, OIBoneInfo> bones { get; private set; }

		// Token: 0x1700031E RID: 798
		// (get) Token: 0x06001D90 RID: 7568 RVA: 0x000BB3E8 File Offset: 0x000B95E8
		// (set) Token: 0x06001D91 RID: 7569 RVA: 0x000BB3F0 File Offset: 0x000B95F0
		public Dictionary<int, OIIKTargetInfo> ikTarget { get; private set; }

		// Token: 0x1700031F RID: 799
		// (get) Token: 0x06001D92 RID: 7570 RVA: 0x000BB3FC File Offset: 0x000B95FC
		// (set) Token: 0x06001D93 RID: 7571 RVA: 0x000BB404 File Offset: 0x000B9604
		public Dictionary<int, List<ObjectInfo>> child { get; private set; }

		// Token: 0x17000320 RID: 800
		// (get) Token: 0x06001D94 RID: 7572 RVA: 0x000BB410 File Offset: 0x000B9610
		// (set) Token: 0x06001D95 RID: 7573 RVA: 0x000BB418 File Offset: 0x000B9618
		public LookAtTargetInfo lookAtTarget { get; set; }

		// Token: 0x06001D96 RID: 7574 RVA: 0x000BB424 File Offset: 0x000B9624
		public override void Save(BinaryWriter _writer, Version _version)
		{
			base.Save(_writer, _version);
			_writer.Write(this.sex);
			this.charFile.Save(_writer);
			this.fileStatus.Save(_writer);
			int num = this.bones.Count;
			_writer.Write(num);
			foreach (KeyValuePair<int, OIBoneInfo> keyValuePair in this.bones)
			{
				int key = keyValuePair.Key;
				_writer.Write(key);
				keyValuePair.Value.Save(_writer, _version);
			}
			num = this.ikTarget.Count;
			_writer.Write(num);
			foreach (KeyValuePair<int, OIIKTargetInfo> keyValuePair2 in this.ikTarget)
			{
				int key2 = keyValuePair2.Key;
				_writer.Write(key2);
				keyValuePair2.Value.Save(_writer, _version);
			}
			num = this.child.Count;
			_writer.Write(num);
			foreach (KeyValuePair<int, List<ObjectInfo>> keyValuePair3 in this.child)
			{
				int key3 = keyValuePair3.Key;
				_writer.Write(key3);
				num = keyValuePair3.Value.Count;
				_writer.Write(num);
				for (int i = 0; i < num; i++)
				{
					keyValuePair3.Value[i].Save(_writer, _version);
				}
			}
			_writer.Write((int)this.kinematicMode);
			_writer.Write(this.animeInfo.group);
			_writer.Write(this.animeInfo.category);
			_writer.Write(this.animeInfo.no);
			for (int j = 0; j < 2; j++)
			{
				_writer.Write(this.handPtn[j]);
			}
			_writer.Write(this.skinRate);
			_writer.Write(this.nipple);
			_writer.Write(this.siru);
			_writer.Write(this.faceOption);
			_writer.Write(this.mouthOpen);
			_writer.Write(this.lipSync);
			this.lookAtTarget.Save(_writer, _version);
			_writer.Write(this.enableIK);
			for (int k = 0; k < 5; k++)
			{
				_writer.Write(this.activeIK[k]);
			}
			_writer.Write(this.enableFK);
			for (int l = 0; l < 7; l++)
			{
				_writer.Write(this.activeFK[l]);
			}
			for (int m = 0; m < 4; m++)
			{
				_writer.Write(this.expression[m]);
			}
			_writer.Write(this.animeSpeed);
			for (int n = 0; n < 2; n++)
			{
				_writer.Write(this.animePattern[n]);
			}
			_writer.Write(this.animeOptionVisible);
			_writer.Write(this.isAnimeForceLoop);
			this.voiceCtrl.Save(_writer, _version);
			if (this.sex == 0)
			{
				_writer.Write(this.visibleSimple);
				_writer.Write(JsonUtility.ToJson(this.simpleColor));
				_writer.Write(this.visibleSon);
				_writer.Write(this.animeOptionParam[0]);
				_writer.Write(this.animeOptionParam[1]);
			}
			_writer.Write(this.neckByteData.Length);
			_writer.Write(this.neckByteData);
			_writer.Write(this.eyesByteData.Length);
			_writer.Write(this.eyesByteData);
			_writer.Write(this.animeNormalizedTime);
			num = ((this.dicAccessGroup == null) ? 0 : this.dicAccessGroup.Count);
			_writer.Write(num);
			if (num != 0)
			{
				foreach (KeyValuePair<int, TreeNodeObject.TreeState> keyValuePair4 in this.dicAccessGroup)
				{
					_writer.Write(keyValuePair4.Key);
					_writer.Write((int)keyValuePair4.Value);
				}
			}
			num = ((this.dicAccessNo == null) ? 0 : this.dicAccessNo.Count);
			_writer.Write(num);
			if (num != 0)
			{
				foreach (KeyValuePair<int, TreeNodeObject.TreeState> keyValuePair5 in this.dicAccessNo)
				{
					_writer.Write(keyValuePair5.Key);
					_writer.Write((int)keyValuePair5.Value);
				}
			}
		}

		// Token: 0x06001D97 RID: 7575 RVA: 0x000BB938 File Offset: 0x000B9B38
		public override void Load(BinaryReader _reader, Version _version, bool _import, bool _tree = true)
		{
			base.Load(_reader, _version, _import, true);
			this.sex = _reader.ReadInt32();
			this.charFile = new CustomParameter(SEX.FEMALE);
			this.charFile.Load(_reader);
			this.fileStatus.Load(_reader, _version);
			int num = _reader.ReadInt32();
			for (int i = 0; i < num; i++)
			{
				int key = _reader.ReadInt32();
				this.bones[key] = new OIBoneInfo(_import ? Studio.GetNewIndex() : -1);
				this.bones[key].Load(_reader, _version, _import, true);
			}
			num = _reader.ReadInt32();
			for (int j = 0; j < num; j++)
			{
				int key2 = _reader.ReadInt32();
				this.ikTarget[key2] = new OIIKTargetInfo(_import ? Studio.GetNewIndex() : -1);
				this.ikTarget[key2].Load(_reader, _version, _import, true);
			}
			num = _reader.ReadInt32();
			for (int k = 0; k < num; k++)
			{
				int key3 = _reader.ReadInt32();
				ObjectInfoAssist.LoadChild(_reader, _version, this.child[key3], _import);
			}
			this.kinematicMode = (OICharInfo.KinematicMode)_reader.ReadInt32();
			this.animeInfo.group = _reader.ReadInt32();
			this.animeInfo.category = _reader.ReadInt32();
			this.animeInfo.no = _reader.ReadInt32();
			for (int l = 0; l < 2; l++)
			{
				this.handPtn[l] = _reader.ReadInt32();
			}
			this.skinRate = _reader.ReadSingle();
			this.nipple = _reader.ReadSingle();
			this.siru = _reader.ReadBytes(5);
			if (_version.CompareTo(new Version(0, 1, 2)) >= 0)
			{
				this.faceOption = _reader.ReadInt32();
			}
			this.mouthOpen = _reader.ReadSingle();
			this.lipSync = _reader.ReadBoolean();
			if (this.lookAtTarget == null)
			{
				this.lookAtTarget = new LookAtTargetInfo(_import ? Studio.GetNewIndex() : -1);
			}
			this.lookAtTarget.Load(_reader, _version, _import, true);
			this.enableIK = _reader.ReadBoolean();
			for (int m = 0; m < 5; m++)
			{
				this.activeIK[m] = _reader.ReadBoolean();
			}
			this.enableFK = _reader.ReadBoolean();
			for (int n = 0; n < 7; n++)
			{
				this.activeFK[n] = _reader.ReadBoolean();
			}
			for (int num2 = 0; num2 < 4; num2++)
			{
				this.expression[num2] = _reader.ReadBoolean();
			}
			this.animeSpeed = _reader.ReadSingle();
			if (_version.CompareTo(new Version(0, 1, 2)) < 0)
			{
				this.animePattern[0] = _reader.ReadSingle();
			}
			else
			{
				for (int num3 = 0; num3 < 2; num3++)
				{
					this.animePattern[num3] = _reader.ReadSingle();
				}
			}
			this.animeOptionVisible = _reader.ReadBoolean();
			this.isAnimeForceLoop = _reader.ReadBoolean();
			this.voiceCtrl.Load(_reader, _version);
			if (this.sex == 0)
			{
				this.visibleSimple = _reader.ReadBoolean();
				this.simpleColor = JsonUtility.FromJson<Color>(_reader.ReadString());
				this.visibleSon = _reader.ReadBoolean();
				this.animeOptionParam[0] = _reader.ReadSingle();
				this.animeOptionParam[1] = _reader.ReadSingle();
			}
			num = _reader.ReadInt32();
			this.neckByteData = _reader.ReadBytes(num);
			num = _reader.ReadInt32();
			this.eyesByteData = _reader.ReadBytes(num);
			this.animeNormalizedTime = _reader.ReadSingle();
			num = _reader.ReadInt32();
			if (num != 0)
			{
				this.dicAccessGroup = new Dictionary<int, TreeNodeObject.TreeState>();
			}
			for (int num4 = 0; num4 < num; num4++)
			{
				int key4 = _reader.ReadInt32();
				this.dicAccessGroup[key4] = (TreeNodeObject.TreeState)_reader.ReadInt32();
			}
			num = _reader.ReadInt32();
			if (num != 0)
			{
				this.dicAccessNo = new Dictionary<int, TreeNodeObject.TreeState>();
			}
			for (int num5 = 0; num5 < num; num5++)
			{
				int key5 = _reader.ReadInt32();
				this.dicAccessNo[key5] = (TreeNodeObject.TreeState)_reader.ReadInt32();
			}
		}

		// Token: 0x06001D98 RID: 7576 RVA: 0x000BBD7C File Offset: 0x000B9F7C
		public override void DeleteKey()
		{
			Studio.DeleteIndex(base.dicKey);
			foreach (KeyValuePair<int, OIBoneInfo> keyValuePair in this.bones)
			{
				Studio.DeleteIndex(keyValuePair.Value.dicKey);
			}
			foreach (KeyValuePair<int, OIIKTargetInfo> keyValuePair2 in this.ikTarget)
			{
				Studio.DeleteIndex(keyValuePair2.Value.dicKey);
			}
			foreach (KeyValuePair<int, List<ObjectInfo>> keyValuePair3 in this.child)
			{
				foreach (ObjectInfo objectInfo in keyValuePair3.Value)
				{
					objectInfo.DeleteKey();
				}
			}
			Studio.DeleteIndex(this.lookAtTarget.dicKey);
		}

		// Token: 0x04001FDD RID: 8157
		public OICharInfo.KinematicMode kinematicMode;

		// Token: 0x04001FDE RID: 8158
		public OICharInfo.AnimeInfo animeInfo = new OICharInfo.AnimeInfo();

		// Token: 0x04001FDF RID: 8159
		public int[] handPtn = new int[2];

		// Token: 0x04001FE0 RID: 8160
		public float mouthOpen;

		// Token: 0x04001FE1 RID: 8161
		public bool lipSync = true;

		// Token: 0x04001FE3 RID: 8163
		public bool enableIK;

		// Token: 0x04001FE4 RID: 8164
		public bool[] activeIK = new bool[]
		{
			true,
			true,
			true,
			true,
			true
		};

		// Token: 0x04001FE5 RID: 8165
		public bool enableFK;

		// Token: 0x04001FE6 RID: 8166
		public bool[] activeFK;

		// Token: 0x04001FE7 RID: 8167
		public bool[] expression;

		// Token: 0x04001FE8 RID: 8168
		public float animeSpeed;

		// Token: 0x04001FE9 RID: 8169
		public float[] animePattern;

		// Token: 0x04001FEA RID: 8170
		public bool animeOptionVisible;

		// Token: 0x04001FEB RID: 8171
		public bool isAnimeForceLoop;

		// Token: 0x04001FEC RID: 8172
		public VoiceCtrl voiceCtrl;

		// Token: 0x04001FED RID: 8173
		public float skinRate;

		// Token: 0x04001FEE RID: 8174
		public float nipple;

		// Token: 0x04001FEF RID: 8175
		public byte[] siru;

		// Token: 0x04001FF0 RID: 8176
		public int faceOption;

		// Token: 0x04001FF1 RID: 8177
		public bool visibleSimple;

		// Token: 0x04001FF2 RID: 8178
		public Color simpleColor;

		// Token: 0x04001FF3 RID: 8179
		public bool visibleSon;

		// Token: 0x04001FF4 RID: 8180
		public float[] animeOptionParam;

		// Token: 0x04001FF5 RID: 8181
		public byte[] neckByteData;

		// Token: 0x04001FF6 RID: 8182
		public byte[] eyesByteData;

		// Token: 0x04001FF7 RID: 8183
		public float animeNormalizedTime;

		// Token: 0x04001FF8 RID: 8184
		public Dictionary<int, TreeNodeObject.TreeState> dicAccessGroup;

		// Token: 0x04001FF9 RID: 8185
		public Dictionary<int, TreeNodeObject.TreeState> dicAccessNo;

		// Token: 0x0200049F RID: 1183
		public enum AccessoryPoint
		{
			// Token: 0x04001FFB RID: 8187
			AP_Head,
			// Token: 0x04001FFC RID: 8188
			AP_Megane,
			// Token: 0x04001FFD RID: 8189
			AP_Nose,
			// Token: 0x04001FFE RID: 8190
			AP_Mouth,
			// Token: 0x04001FFF RID: 8191
			AP_Earring_L,
			// Token: 0x04002000 RID: 8192
			AP_Earring_R,
			// Token: 0x04002001 RID: 8193
			AP_Neck,
			// Token: 0x04002002 RID: 8194
			AP_Chest,
			// Token: 0x04002003 RID: 8195
			AP_Waist,
			// Token: 0x04002004 RID: 8196
			AP_Tikubi_L,
			// Token: 0x04002005 RID: 8197
			AP_Tikubi_R,
			// Token: 0x04002006 RID: 8198
			AP_Shoulder_L,
			// Token: 0x04002007 RID: 8199
			AP_Shoulder_R,
			// Token: 0x04002008 RID: 8200
			AP_Arm_L,
			// Token: 0x04002009 RID: 8201
			AP_Arm_R,
			// Token: 0x0400200A RID: 8202
			AP_Wrist_L,
			// Token: 0x0400200B RID: 8203
			AP_Wrist_R,
			// Token: 0x0400200C RID: 8204
			AP_Hand_L_NEO,
			// Token: 0x0400200D RID: 8205
			AP_Hand_R,
			// Token: 0x0400200E RID: 8206
			AP_Index_L,
			// Token: 0x0400200F RID: 8207
			AP_Middle_L,
			// Token: 0x04002010 RID: 8208
			AP_Ring_L,
			// Token: 0x04002011 RID: 8209
			AP_Index_R,
			// Token: 0x04002012 RID: 8210
			AP_Middle_R,
			// Token: 0x04002013 RID: 8211
			AP_Ring_R,
			// Token: 0x04002014 RID: 8212
			AP_Leg_L,
			// Token: 0x04002015 RID: 8213
			AP_Leg_R,
			// Token: 0x04002016 RID: 8214
			AP_Ankle_L,
			// Token: 0x04002017 RID: 8215
			AP_Ankle_R
		}

		// Token: 0x020004A0 RID: 1184
		public enum IKTargetEN
		{
			// Token: 0x04002019 RID: 8217
			Body,
			// Token: 0x0400201A RID: 8218
			LeftShoulder,
			// Token: 0x0400201B RID: 8219
			LeftArmChain,
			// Token: 0x0400201C RID: 8220
			LeftHand,
			// Token: 0x0400201D RID: 8221
			RightShoulder,
			// Token: 0x0400201E RID: 8222
			RightArmChain,
			// Token: 0x0400201F RID: 8223
			RightHand,
			// Token: 0x04002020 RID: 8224
			LeftThigh,
			// Token: 0x04002021 RID: 8225
			LeftLegChain,
			// Token: 0x04002022 RID: 8226
			LeftFoot,
			// Token: 0x04002023 RID: 8227
			RightThigh,
			// Token: 0x04002024 RID: 8228
			RightLegChain,
			// Token: 0x04002025 RID: 8229
			RightFoot
		}

		// Token: 0x020004A1 RID: 1185
		public enum KinematicMode
		{
			// Token: 0x04002027 RID: 8231
			None,
			// Token: 0x04002028 RID: 8232
			FK,
			// Token: 0x04002029 RID: 8233
			IK
		}

		// Token: 0x020004A2 RID: 1186
		public class AnimeInfo
		{
			// Token: 0x06001D9A RID: 7578 RVA: 0x000BBEF0 File Offset: 0x000BA0F0
			public void Set(int _group, int _category, int _no)
			{
				this.group = _group;
				this.category = _category;
				this.no = _no;
			}

			// Token: 0x17000321 RID: 801
			// (get) Token: 0x06001D9B RID: 7579 RVA: 0x000BBF08 File Offset: 0x000BA108
			public bool exist
			{
				get
				{
					return this.group != -1 & this.category != -1 & this.no != -1;
				}
			}

			// Token: 0x06001D9C RID: 7580 RVA: 0x000BBF30 File Offset: 0x000BA130
			public void Copy(OICharInfo.AnimeInfo _src)
			{
				this.group = _src.group;
				this.category = _src.category;
				this.no = _src.no;
			}

			// Token: 0x0400202A RID: 8234
			public int group;

			// Token: 0x0400202B RID: 8235
			public int category;

			// Token: 0x0400202C RID: 8236
			public int no;
		}
	}
}
